package middleware

import (
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
)

// Logger 中间件
func Logger() gin.HandlerFunc {
	return func(context *gin.Context) {
		host := context.Request.Host
		url := context.Request.URL
		method := context.Request.Method

		fmt.Printf("%s::%s \t %s \t %s", time.Now().Format("2005-01-02 15:15:15"), host, url, method)

		// before request
		// 中间件需要： 通过 Next() 往下传递
		context.Next()

		// after request
		fmt.Println(context.Writer.Status())
	}
}
